/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-05-21
 * Time: 22:10
 */
public class Deom5 {
    private static class MyRunnable implements Runnable {
        @Override
        public void run() {
            //两种⽅法均可以
            while (!Thread.interrupted()) {
                //while (!Thread.currentThread().isInterrupted()) {
                System.out.println(Thread.currentThread().getName()
                        + ": 别管我，我忙着转账呢 !");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println(Thread.currentThread().getName()
                            + ": 有内⻤，终⽌交易！ ");
                    //注意此处的break
                    break;
                }
            }
            System.out.println(Thread.currentThread().getName()
                    + ": 啊！险些误了⼤事 ");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyRunnable target = new MyRunnable();
        Thread thread = new Thread(target, " 李四");
        System.out.println(Thread.currentThread().getName()
                + ": 让李四开始转账。");
        thread.start();
        Thread.sleep(10 * 1000);
        System.out.println(Thread.currentThread().getName()
                + ":⽼板来电话了，得赶紧通知李四对⽅是个骗⼦！ ");
        thread.interrupt();
    }


//        Thread t1 = new Thread(() -> {
//            while (true) {
//                System.out.println("打印thread");
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//        });
//        t1.start();
//
//        while(true) {
//            System.out.println("打印main");
//            Thread.sleep(1000);
//        }
//    }
}
